﻿@page "/data-monitor"
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Components.QuickGrid
@using BlazorAppAuth.Models
@using BlazorAppAuth.Data
@inject IDbContextFactory<BlazorAppAuth.Data.BlazorAppAuthContext> DbFactory
@implements IAsyncDisposable

<QuickGrid Items="context.Order" Class="table">
    <PropertyColumn Property="@(o => o.Id)" Title="ID" />
    <PropertyColumn Property="@(o => o.OrderId)" Title="订单编号" />
    <PropertyColumn Property="@(o => o.OrderType)" Title="订单类型" />
    <PropertyColumn Property="@(o => o.UserType)" Title="用户类型" />
    <PropertyColumn Property="@(o => o.UserName)" Title="用户名" />
    <PropertyColumn Property="@(o => o.StartTime)" Title="启动时间" />
    <PropertyColumn Property="@(o => o.OrderTime)" Title="下单时间" />
    <PropertyColumn Property="@(o => o.Quantity)" Title="数量" />
    <PropertyColumn Property="@(o => o.Priority)" Title="优先级" />
    <PropertyColumn Property="@(o => o.AssemblyTime)" Title="装配时间" />
    <PropertyColumn Property="@(o => o.DrillingTime)" Title="钻孔时间" />
    <PropertyColumn Property="@(o => o.AssemblyCount)" Title="装配次数" />
    <PropertyColumn Property="@(o => o.DrillingCount)" Title="钻孔次数" />
    <PropertyColumn Property="@(o => o.OrderStatus)" Title="订单状态" />
    <PropertyColumn Property="@(o => o.ElectricityConsumption)" Title="订单用电量（w·h）" />
    <PropertyColumn Property="@(o => o.GasConsumption)" Title="订单用气量（L）" />
</QuickGrid>

@code {
    BlazorAppAuthContext context = default!;
    [CascadingParameter]
    private Task<AuthenticationState> authenticationStateTask { get; set; }
    public async Task CheckLogin()
    {
        var authState = await authenticationStateTask;
        var user = authState.User;

        if (!user.Identity.IsAuthenticated)
        {
            NavigationManager.NavigateTo("/login");
        }

    }


    protected override async void OnInitialized()
    {
        await CheckLogin();
        context = DbFactory.CreateDbContext();
    }

    public async ValueTask DisposeAsync() => await context.DisposeAsync();
}

